<template>
  <div class="home">
    <h1>Home</h1>
    <el-button 
      type="primary" 
      :loading="loading"
      @click="handleClick"
    >
      Primary Button
    </el-button>
    <el-alert
      v-if="error"
      :title="error"
      type="error"
      show-icon
      class="mt-4"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { useAppStore } from '@/stores'

export default defineComponent({
  name: 'HomeView',
  setup() {
    const store = useAppStore()

    const handleClick = async () => {
      try {
        store.setLoading(true)
        store.setError(null)
        // Simulate async operation
        await new Promise(resolve => setTimeout(resolve, 1000))
      } catch (err) {
        store.setError('An error occurred')
      } finally {
        store.setLoading(false)
      }
    }

    return {
      loading: store.loading,
      error: store.error,
      handleClick
    }
  }
})
</script>

<style scoped>
.home {
  padding: 20px;
}

.mt-4 {
  margin-top: 1rem;
}
</style>
